package com.appointment.controller.admin;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.appointment.dao.ConfirmDao;
import com.appointment.entity.Confirm;
import com.appointment.entity.Score;
import com.appointment.entity.confirmPage;
import com.appointment.web.PrintTimeFunction;
/**
 * 打印证明信息
 * @author WSD
 *
 */
@Controller
@RequestMapping("/admin")
public class AdminConfirmController {
	
	@Resource
	ConfirmDao confirmdao;
	
	
	
	//未处理信息
	@Transactional(rollbackFor={Exception.class})
	@RequestMapping("/getconfirmMes")
	public String getConfirmMes(@RequestParam(value="thispage", required=false) String thispage, Model model){
		if(thispage!=null&&!thispage.matches("[0-9]+")){
			return "redirect:/error";
		}
		confirmPage page = new confirmPage();
		if(thispage!=null){
			page.setThispage(Integer.parseInt(thispage));
		}
		List<Confirm> list = confirmdao.findConfirms(page);
		int num = confirmdao.findConnum();
		page.setCountpage(num/page.getCountrow()+1);
		page.setList(list);
		for(Confirm c :list){
			c.setDay(PrintTimeFunction.getNiceDate(c.getTime()));
		}
		model.addAttribute("page", page);
		return "admin/adminCon";
		
	}
	
	//处理信息
	@Transactional(rollbackFor={Exception.class})
	@RequestMapping("/getconfirmedMes")
	public String getConfirmedMes(@RequestParam(value="thispage", required=false) String thispage, Model model){
		if(thispage!=null&&!thispage.matches("[0-9]+")){
			return "redirect:/error";
		}
		confirmPage page = new confirmPage();
		if(thispage!=null){
			page.setThispage(Integer.parseInt(thispage));
		}
		List<Confirm> list = confirmdao.findConfirmed(page);
		int num = confirmdao.findConnumed();
		page.setCountpage(num/page.getCountrow()+1);
		page.setList(list);
		for(Confirm c :list){
			c.setDay(PrintTimeFunction.getNiceDate(c.getTime()));
		}
		model.addAttribute("page", page);
		return "admin/adminConwc";
		
	}
	
	@RequestMapping("/getconfirmStu")
	public String getconfirmStu(String stu_number, Model model){
		Confirm confirm = confirmdao.findConfirmedByStuNumber(stu_number);
		if(confirm==null){
			return "redirect:/error";
		}
		model.addAttribute("confirm", confirm);
		return "admin/confirmqui";
	}
	
	//不处理
	@RequestMapping("/errorconfirmStu")
	public String errorconfirmStu(String stu_number){
		Confirm confirm = confirmdao.findConfirmedByStuNumber(stu_number);
		if(confirm==null){
			return "redirect:/error";
		}
		confirmdao.errorConfrimById(confirm.getId());
		return "redirect:/admin/getconfirmMes";
	}
	
	@RequestMapping("/getconfirms")
	public String getconfirms(String stu_number, Model model){
		Confirm confirm = confirmdao.findConfirmedByStuNumber(stu_number);
		if(confirm==null){
			return "redirect:/error";
		}
		
		model.addAttribute("confirm", confirm);
		return "admin/dayin";
	}
	
	@RequestMapping("/updateconfirmStu")
	public String updateconfirmStu(String stu_number){
		Confirm confirm = confirmdao.findConfirmedByStuNumber(stu_number);
		if(confirm==null){
			return "redirect:/error";
		}
		confirmdao.updateConfrimById(confirm.getId());
		return "redirect:/admin/getconfirmMes";
	}
}
